<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head th:include="public/page_css::page_css ('新增客户档案')"/>
<meta charset="UTF-8"/>
<title>Title</title>
<!-- load css -->

<link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/css/font/iconfont.css}" media="all"/>
<link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/js/layui/css/layui.css}" media="all"/>
<link rel="stylesheet" type="text/css" th:href="@{/css/main.css}" media="all"/>
<style>
    .layui-form-label {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
</style>

<body>
<div class="layui-fluid larry-wrapper" id="div1">
    <div class="layui-row layui-col-space30" >
        <div class="layui-col-xs24">
            <section class="panel panel-padding">
                <form id="form" class="layui-form layui-form-pane" action="">
                    &nbsp;
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">货主名称</label>
                            <div class="layui-input-inline">

                                <input type="text" th:value="${hzmc}"  readonly  class="layui-input "/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label"><font color="red" style="margin-right:10px">*</font>客户编号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="khbh" required="required" jq-verify="required"
                                       jq-error="请输入客户编号" lay-verify="required" placeholder="请输入客户编号" autocomplete="off"
                                       class="layui-input "/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label"><font color="red"
                                                                  style="margin-right:10px">*</font>客户名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="khmc" required="required" jq-verify="required"
                                       jq-error="请输入客户名称" lay-verify="required" placeholder="请输入客户名称" autocomplete="off"
                                       class="layui-input "/>
                            </div>
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label"><font color="red"
                                                                  style="margin-right:10px">*</font>客户类型</label>
                            <div class="layui-input-inline">
                                <select name="khlx" id="khlx">
                                    <option value="0">收货人</option>
                                    <option value="1">承运人</option>
                                    <option value="2">仓库</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label"><font color="red"
                                                                  style="margin-right:10px">*</font>省份</label>
                            <div class="layui-input-inline">
                                <select name="sheng" id="sheng" lay-verify="required" lay-filter="sheng">

                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label"><font color="red"
                                                                  style="margin-right:10px">*</font>城市</label>
                            <div class="layui-input-inline">
                                <select name="shi" id="shi" lay-verify="required">
                                </select>
                            </div>
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label"><font color="red"
                                                                  style="margin-right:10px">*</font>路线</label>
                            <div class="layui-input-inline">
                                <select lay-ignore="lay-ignore" data-required="data-required"
                                        class="js-data-example-ajax" name="lxid" id="selectId" select2
                                        style="width: 193px">
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label"><font color="red"
                                                                  style="margin-right:10px">*</font>详细地址</label>
                            <div class="layui-input-inline">
                                <input type="text" name="dz" required="required" jq-verify="required" jq-error="请输入详细地址"
                                       lay-verify="required" placeholder="请输入详细地址" autocomplete="off"
                                       class="layui-input "/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" title="联系人姓名"><font color="red"
                                                                                style="margin-right:10px">*</font>联系人姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="lxrxm" required="required" jq-verify="required"
                                       jq-error="请输入联系人姓名" lay-verify="required"
                                       placeholder="请输入联系人姓名" autocomplete="off"
                                       class="layui-input "/>
                            </div>
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label"><font color="red"
                                                                  style="margin-right:10px">*</font>联系电话</label>
                            <div class="layui-input-inline">
                                <input type="text" name="lxrdh" required="required" jq-verify="required"
                                       jq-error="请输入联系人电话"
                                       lay-verify="required|phone|number"  placeholder="请输入联系人电话" autocomplete="off"
                                       class="layui-input "/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label"><font color="red"
                                                                  style="margin-right:10px">*</font>客户等级</label>
                            <div class="layui-input-inline">
                                <input type="text" name="khdj" required="required" jq-verify="required"
                                       jq-error="请输入客户等级"
                                       lay-verify="required|zhengshu" placeholder="客户等级" autocomplete="off"
                                       class="layui-input "/>
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" jq-filter="submit" lay-submit="" lay-filter="addCustomer">立即提交
                            </button>
                            <button type="reset" class="layui-btn layui-btn-primary" style="background-color: #1e9fff; color: white;">重置</button>
                        </div>
                    </div>

                </form>
            </section>
        </div>
    </div>
</div>


<div id="div2" hidden="hidden" >
    <div class="layui-fluid larry-wrapper">
        <div style=" margin-left: 10px;font-weight: bold;">
            <h4> 收货地址管理</h4>
            <hr/>
        </div>
        <div class="layui-card">
            <form id="form1" class="layui-form layui-form-pane" action="">
                <div>&nbsp;</div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">详细地址</label>
                        <div class="layui-input-inline">
                            <input type="text" name="xxdz" id="xxdz" placeholder="详细地址" lay-verify="required" autocomplete="off" class="layui-input " />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">联系人姓名</label>
                        <div class="layui-input-inline">
                            <input type="text" name="lxr" id="lxr" placeholder="联系人姓名" lay-verify="required" autocomplete="off" class="layui-input "/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">联系人电话</label>
                        <div class="layui-input-inline">
                            <input type="text" name="lxdh" id="lxdh" placeholder="联系人电话" lay-verify="required|phone|number" autocomplete="off" class="layui-input "/>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">

                    <div class="layui-inline">
                        <label class="layui-form-label">省份</label>
                        <div class="layui-input-inline">
                            <select name="sheng" id="sheng2" lay-verify="required" lay-filter="sheng2">

                            </select>
                        </div>
                        <!-- <div class="layui-input-inline">
                             <input type="text" name="sheng" id="sheng" placeholder="省份" autocomplete="off" class="layui-input "/>
                         </div>-->
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">城市</label>
                        <div class="layui-input-inline">
                            <select name="shi" id="shi2" lay-verify="required">
                            </select>
                        </div>
                        <!--<div class="layui-input-inline">
                            <input type="text" name="shi" id="shi" placeholder="城市" autocomplete="off" class="layui-input "/>
                        </div>-->
                    </div>
                </div>
                <input type="hidden"  id="sskhid1"  name="sskhid">
                <input type="hidden"id="id" name="id">
                <div style="  border-bottom: 1px solid; border-bottom-color: #d5cece; padding: 20px;">
                    <!--  <a class="layui-btn layui-btn-sm layui-btn-normal " id="addbtn">
                          <i class="layui-icon">&#x1005;</i> 添加
                      </a>
                      <a class="layui-btn layui-btn-sm" id="savebtn">
                          <i class="layui-icon">&#x1005;</i> 保存编辑
                      </a>-->
                    <button class="layui-btn" jq-filter="submit" lay-submit="" lay-filter="addbtn">添加
                    </button>
                    <button class="layui-btn" jq-filter="submit" lay-submit="" lay-filter="savebtn">保存编辑
                    </button>
                </div>
            </form>
            <div>

                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline" style="width: 190px">
                        <label class="layui-form-label" style=" width: 100px;">详细地址</label>
                        <div class="layui-inline">
                            <input type="text" name="xxdz" placeholder="详细地址"  class="layui-input" style="width: 190px">
                        </div>
                    </div>
                    <div class="layui-inline" style="width: 190px">
                        <label class="layui-form-label" style=" width: 100px;">联系人</label>
                        <div class="layui-inline">
                            <input type="text" name="lxr" placeholder="联系人"  class="layui-input" style="width: 190px">
                        </div>
                    </div>

                    <div class="layui-inline inline-search-btn"   style="  margin-top: 40px; margin-left: 40px;" >
                        <a class="layui-btn layui-btn-normal" data-type="reload" id="search_button"> 搜索 </a>
                    </div>
                    <div class="layui-inline inline-reset-btn"  style="  margin-top: 40px;" >
                        <button type="reset" class="layui-btn layui-btn-primary" style="background-color: #40AFFE">重置</button>
                    </div>
                </form>
                <div class="layui-col-xs24" style="max-height: 300px;overflow: auto">
                    <table data-height="300" id="table1" style="word-break:break-all; word-wrap:break-word;"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="div3" hidden="hidden">
    <div class="layui-fluid larry-wrapper">
        <div style="    margin-left: 10px;font-weight: bold;">
            <h4> 所属仓库管理</h4>
        </div>
        <div class="layui-card">
            <form id="form2" class="layui-form layui-form-pane" action="">
                <div>&nbsp;</div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">车牌号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="cph" id="cph" placeholder="车牌号" lay-verify="required" autocomplete="off" class="layui-input " />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">司机姓名</label>
                        <div class="layui-input-inline">
                            <input type="text" name="sjxm" id="sjxm" placeholder="联系人姓名" lay-verify="required" autocomplete="off" class="layui-input "/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">司机电话</label>
                        <div class="layui-input-inline">
                            <input type="text" name="sjdh" id="sjdh"  data-required   jq-verify="required" lay-verify="required|phone|number"   placeholder="联系人电话" autocomplete="off" class="layui-input "/>
                        </div>
                    </div>
                </div>
                <input type="hidden"  id="sskhid2" name="sskhid">
                <input type="hidden" id="clid" name="id">

                <div style=" border-bottom: 1px solid; border-bottom-color: #d5cece; padding: 20px;">

                    <button class="layui-btn" jq-filter="submit" lay-submit="" lay-filter="addbtn2">添加
                    </button>
                    <button class="layui-btn" jq-filter="submit" lay-submit="" lay-filter="savebtn2">保存编辑
                    </button>
                </div>
            </form>
            <div>


                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm2">
                    <div class="layui-inline" style="width: 190px">
                        <label class="layui-form-label" style=" width: 100px;">车牌号</label>
                        <div class="layui-inline">
                            <input type="text" name="cph" placeholder="车牌号"  class="layui-input" style="width: 190px">
                        </div>
                    </div>
                    <div class="layui-inline" style="width: 190px">
                        <label class="layui-form-label" style=" width: 100px;">司机电话</label>
                        <div class="layui-inline">
                            <input type="text" name="sjdh" placeholder="司机电话"  class="layui-input" style="width: 190px">
                        </div>
                    </div>

                    <div class="layui-inline inline-search-btn"   style="  margin-top: 40px; margin-left: 40px;" >
                        <a class="layui-btn layui-btn-normal" data-type="reload" id="search_button2"> 搜索 </a>
                    </div>
                    <div class="layui-inline inline-reset-btn"  style="  margin-top: 40px;" >
                        <button type="reset" class="layui-btn layui-btn-primary" style="background-color: #40AFFE">重置</button>
                    </div>
                </form>
                <div class="layui-col-xs24" style="max-height: 300px;overflow: auto">
                    <table data-height="300" id="table2" style="word-break:break-all; word-wrap:break-word;"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="div4" hidden="hidden">
    <div class="layui-fluid larry-wrapper">
        <div style="    margin-left: 10px;font-weight: bold;">
            <h4> 所属仓库管理</h4>
        </div>
        <div class="layui-card">
            <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm3">
                <input type="hidden"  id="sskhid3" name="sskhid">
            </form>
            <div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body" >
                    <div class="pro">
                        <table id="table3"  class="table text-nowrap" style="word-break:break-all; word-wrap:break-word;"></table>
                    </div>
                </section>
                <div class="group-button" style="float:right;margin-bottom: 10px">
                    <a class="layui-btn layui-btn-sm layui-btn-normal warehouseSave">
                        <i class="layui-icon">&#x1005;</i> 保存
                    </a>
                    <a class="layui-btn layui-btn-sm layui-btn-normal warehouseSaveCloses">
                        <i class="layui-icon">&#x1005;</i> 取消
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" th:src="@{/plugin/layui/js/layui/layui.js}"></script>
<script type="text/javascript" th:src="@{/plugin/layui/js/version.js}"></script>
<script th:src="@{/plugin/layui/js/common.js}"></script>
<div th:include="public/public_js::public_js"></div>
<script>
    $(function () {

        //加载省份
        $("#sheng,#sheng2").html("");
        var str = "<option value=''>==请选择===</option>";
        $.ajax({
            type: "GET",
            url: "/zxsswms/wmscityinfo/selectProvice/1",
            dataType: "JSON",
            async: false,
            success: function (data) {
                console.info(data);
                //从服务器获取数据进行绑定
                $.each(data, function (i, item) {
                    console.info("item.cityname" + item.cityname);
                    console.info(item.citycode);
                    str += "<option value=" + item.cityname + " code=" + item.citycode + ">" + item.cityname + "</option>";
                })
                //将数据添加到省份这个下拉框里面
                $("#sheng").append(str);
                $("#sheng2").append(str);

            },
            error: function () {
                alert("Error");
            }
        });
    });

</script>
<script>
    //	回车查询
    document.onkeydown = function(event) {
        e = event ? event : (window.event ? window.event : null);
        if (e.keyCode == 13) {
            //执行的方法
            $('#search_button').click();
            $('#search_button2').click();
        }
    };

    function cityBind() {
        var sheng = $("#sheng").attr("value");
        //判断省份这个下拉框选中的值是否为空
        if (sheng == "") {
            return;
        }
        $("#shi").html("");
        var str = "<option value=''>==请选择===</option>";
        $.ajax({
            type: "POST",
            url: "/xbzzwms/wmscityinfo/selectProvice/" + sheng,
            dataType: "JSON",
            async: false,
            success: function (data) {
                //从服务器获取数据进行绑定
                $.each(data, function (i, item) {
                    str += "<option value=" + item.citycode + ">" + item.cityname + "</option>";
                })
                //将数据添加到省份这个下拉框里面
                $("#shi").append(str);
            },
            error: function () {
                alert("Error");
            }
        });
    }

    layui.use(['myform', 'zzpUtils', 'form'], function () {
        var form = layui.form,
            zzpUtils = layui.zzpUtils;

        //select2 查路线
        $('#selectId').select2({
            ajax: {
                url: "/zxsswms/wmsCustomerFiles/baseSelectLine",//路径
                dataType: 'json',
                type: 'POST',
                contentType: "application/json",
                data: function (params) {
                    var query = {
                        mc: params.term
                    };
                    return JSON.stringify(query);
                },
                processResults: function (data) {
                    var arr = new Array();
                    if (data) {
                        for (var i = 0; i < data.length; i++) {
                            arr.push({id: data[i].id, text: data[i].xlmc});
                        }
                    }
                    console.log(arr);
                    return {
                        results: arr
                    };
                },
                cache: true
            },
            language: "zh-CN",
            placeholder: '请输入查询货品种类',
            allowClear: true
        });

        form.verify({
            zhengshu: function (value) {
                var result = zhengshu(value);
                if (result != "Y") {
                    return result;
                }
            }
        });
        function zhengshu(value) {
            /*var reg = /^\+?((0|([1-9]+\d*))|((0\.\d+)|([1-9]+\d*\.\d+)))$/;*/
            var reg =  /^([1-9]\d*|[0]{1,1})$/;
            if (reg.test(value)) {
                return "Y";
            }
            return "请输入正整数";
        }
        //保存客户档案
        form.on("submit(addCustomer)", function (data) {
            if($("#selectId").val()==null||selectId==""){
                layer.msg("路线不可为空");
            }else {
                zzpUtils.confirm("是否确定添加", function (index) {
                    zzpUtils.action({
                        url: "/wmsCustomerFile/save",
                        data: JSON.stringify(data.field),
                        success: function (data) {
                            setTimeout(function () {
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                /*     parent.layer.close(index); //再执行关闭*/
                                console.info(data);
                                top.layer.msg(data.title + "," + data.message);
                                if (data.messageType == 2) {
                                    $("#sskhid1").val(data.data.id);
                                    $("#sskhid2").val(data.data.id);
                                    $("#sskhid3").val(data.data.id);
                                    if ($("#khlx").val() == 0) {
                                        $("#div1").hide();
                                        $("#div2").show();
                                    } else if ($("#khlx").val() == 1) {
                                        $("#div1").hide();
                                        $("#div3").show();
                                    } else if ($("#khlx").val() == 2) {
                                        $("#div1").hide();
                                        $("#div4").show();
                                    }
                                }
                                //刷新父页面1
                            }, 500);
                        }, error: function (xhr, textStatus) {
                            console.log(textStatus);
                            console.log(xhr)
                        }
                    })
                })
            }
            return false;

        });
        form.on('select(sheng)', function (data) {
            console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象
            var sheng = $("#sheng").find("option:selected").attr("code");
            //判断省份这个下拉框选中的值是否为空
            if (sheng == "") {
                return;
            }
            $("#shi").html("");
            var str = "<option value=''>==请选择===</option>";
            $.ajax({
                type: "GET",
                url: "/zxsswms/wmscityinfo/selectProvice/" + sheng,
                dataType: "JSON",
                async: false,
                success: function (data) {
                    //从服务器获取数据进行绑定
                    $.each(data, function (i, item) {
                        str += "<option value=" + item.cityname + ">" + item.cityname + "</option>";
                    })
                    console.info(str);
                    //将数据添加到省份这个下拉框里面
                    $("#shi").append(str);
                    console.info($("#shi").html());
                    form.render('select');
                },
                error: function () {
                    alert("Error");
                }
            });

        });

        form.on('select(sheng2)', function (data) {
            console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象
            var sheng = $("#sheng2").find("option:selected").attr("code");
            //判断省份这个下拉框选中的值是否为空
            if (sheng == "") {
                return;
            }

            $("#shi2").html("");
            var str = "<option value=''>==请选择===</option>";
            $.ajax({
                type: "GET",
                url: "/zxsswms/wmscityinfo/selectProvice/" + sheng,
                dataType: "JSON",
                async: false,
                success: function (data) {
                    //从服务器获取数据进行绑定
                    $.each(data, function (i, item) {
                        str += "<option value=" + item.cityname + ">" + item.cityname + "</option>";
                    })
                    console.info(str);
                    //将数据添加到省份这个下拉框里面
                    $("#shi2").append(str);
                    console.info("第三方斯蒂芬");
                    console.info($("#shi2").html());
                    form.render('select');
                },
                error: function () {
                    alert("Error");
                }
            });

        });
        window.operateEvent ={
            "click .layui-btn-primary":function (e, value, row, index) {

            },
            //地址编辑
            "click #editRow":function (e, value, row, index) {
                console.info(row);
                $.ajax({
                    type: 'get',
                    url: '/zxsswms/wmsCustomerFileConsignee/findOne/'+row.id,
                    contentType: "application/json",
                    async: false,
                    success: function (data) {
                        $("#xxdz").val(data.xxdz);
                        $("#lxr").val(data.lxr);
                        $("#lxdh").val(data.lxdh);
                        //$('#sheng2').html('<option value="' + data.sheng + '">' + data.sheng + '</option>').trigger("change");
                        /*  var optionInf = optionRendering(data.sheng, 'sheng', 'sheng');*/
                        $("#sheng2").val(data.sheng);
                        var str;
                        $.ajax({
                            type: "GET",
                            url: "/zxsswms/wmscityinfo/getIdByName/" + data.sheng,
                            dataType: "JSON",
                            async: false,
                            success: function (data) {
                                $.ajax({
                                    type: "GET",
                                    url: "/zxsswms/wmscityinfo/selectProvice/" + data.citycode,
                                    dataType: "JSON",
                                    async: false,
                                    success: function (data) {
                                        //从服务器获取数据进行绑定
                                        $.each(data, function (i, item) {
                                            str += "<option value=" + item.cityname + ">" + item.cityname + "</option>";
                                        })
                                        console.info(str);
                                        //将数据添加到省份这个下拉框里面
                                        $("#shi2").append(str);
                                        console.info("第三方斯蒂芬");
                                        console.info($("#shi2").html());
                                        form.render('select');
                                    },
                                    error: function () {
                                        alert("Error");
                                    }
                                });
                            },
                            error: function () {
                                alert("Error");
                            }
                        });

                        $('#shi2').val(data.shi);
                        form.render();
                        $("#id").val(data.id);
                        $("#sskhid1").val(data.sskhid);
                        /*  zzpUtils.loadJsonDataToForm(data);*/
                        console.log(data);
                    }
                })

            },
            //地址启用
            "click #enable": function (e, value, row, index) {
                layer.confirm('您将启用该收货地址。', {icon: 3, title: '确认启用？'}, function (index) {
                    var id = [];
                    id.push(row.id);
                    $.ajax({
                        type: 'post',
                        url: '/zxsswms/wmsCustomerFileConsignee/activation',
                        contentType: "application/json",
                        async: false,
                        data: JSON.stringify({
                            ids: id,
                        }),
                        success: function (res) {
                            console.log(res);
                            setTimeout(function () {
                                /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                 parent.layer.close(index); //再执行关闭
                                 console.info(data);*/
                                top.layer.msg(res.title + "," + res.message);
                                zzpUtils.refreshTable("#table1");
                                //刷新父页面
                            }, 500);
                        }
                    })
                    layer.close(index);
                });

            },
            //地址删除
            "click #deleteBtn": function (e, value, row, index) {
                layer.confirm('您将作废该收货地址。', {icon: 3, title: '确认作废？'}, function (index) {
                    console.log('触发了删除', index, row, value);
                    var tabledata = $table1.bootstrapTable('getData');
                    tabledata = tabledata.filter(function (item) {
                        return item.uuid !== row.uuid;
                    });
                    var id = [];
                    id.push(row.id);
                    $.ajax({
                        type: 'post',
                        url: '/zxsswms/wmsCustomerFileConsignee/cancel',
                        contentType: "application/json",
                        async: false,
                        data: JSON.stringify({
                            ids: id,
                        }),
                        success: function (res) {
                            setTimeout(function () {
                                zzpUtils.refreshTable("#table1");
                                /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                 parent.layer.close(index); //再执行关闭
                                 console.info(data);*/
                                top.layer.msg(res.title + "," + res.message);
                                //刷新父页面
                            }, 500);
                        }
                    })
                    layer.close(index);
                })
            },
            //取消默认
            "click #default": function (e, value, row, index) {
                layer.confirm('您将信息设为默认。', {icon: 3, title: '确认设为默认？'}, function (index) {
                    $.ajax({
                        type: 'get',
                        url: '/zxsswms/wmsCustomerFileConsignee/acquiesceIn/' + row.id,
                        contentType: "application/json",
                        async: false,
                        success: function (data) {
                            setTimeout(function () {
                                zzpUtils.refreshTable("#table1");
                                /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                 parent.layer.close(index); //再执行关闭
                                 console.info(data);*/
                                top.layer.msg(res.title + "," + res.message);
                                //刷新父页面
                            }, 500);
                        },
                        error: function () {
                            alert("Error");
                        }
                    });
                    layer.close(index);
                })
            },
            //默认
            "click #undefault": function (e, value, row, index) {
                layer.confirm('您将信息取消默认。', {icon: 3, title: '确认取消默认？'}, function (index) {
                    $.ajax({
                        type: 'get',
                        url: '/zxsswms/wmsCustomerFileConsignee/removeAcquiesceIn/' + row.id,
                        contentType: "application/json",
                        async: false,
                        success: function (data) {
                            setTimeout(function () {
                                zzpUtils.refreshTable("#table1");
                                /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                 parent.layer.close(index); //再执行关闭
                                 console.info(data);*/
                                top.layer.msg(res.title + "," + res.message);
                                //刷新父页面
                            }, 500);
                        },
                        error: function () {
                            alert("Error");
                        }
                    });
                    layer.close(index);
                })
            },



            //车辆编辑
            "click #editRow2":function (e, value, row, index) {
                console.info(row);
                $("#cph").val(row.cph);
                $("#sjdh").val(row.sjdh);
                $("#sjxm").val(row.sjxm);
                $("#clid").val(row.id);
            },
            //车辆删除
            "click #deleteBtn2": function (e, value, row, index) {
                layer.confirm('您将删除承运车辆。', {icon: 3, title: '确认删除？'}, function (index) {
                    console.log('触发了删除', index, row, value);
                    var tabledata = $table2.bootstrapTable('getData');
                    tabledata = tabledata.filter(function (item) {
                        return item.uuid !== row.uuid;
                    });
                    var id = [];
                    id.push(row.id);
                    $.ajax({
                        type: 'post',
                        url: '/zxsswms/wmsCustomerFileCarrier/cancel',
                        contentType: "application/json",
                        async: false,
                        data: JSON.stringify({
                            ids: id,
                        }),
                        success: function (res) {
                            setTimeout(function () {
                                zzpUtils.refreshTable("#table2");
                                /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                 parent.layer.close(index); //再执行关闭
                                 console.info(data);*/
                                top.layer.msg(res.title + "," + res.message);
                                //刷新父页面
                            }, 500);
                        }
                    })
                    layer.close(index);
                })

            },
            //车辆启用
            "click #enable2":function (e, value, row, index) {
                layer.confirm('您将启用承运车辆。', {icon: 3, title:'确认启用？'}, function(index){
                    //do something
                    var id = [];
                    id.push(row.id);
                    $.ajax({
                        type: 'post',
                        url: '/zxsswms/wmsCustomerFileCarrier/activation',
                        contentType: "application/json",
                        async: false,
                        data: JSON.stringify({
                            ids: id,
                        }),
                        success: function (res) {

                            console.log(res);
                            setTimeout(function(){
                                /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                 parent.layer.close(index); //再执行关闭
                                 console.info(data);*/
                                top.layer.msg(res.title+","+res.message);
                                zzpUtils.refreshTable("#table2");
                                //刷新父页面
                            },500);
                        }
                    })
                    layer.close(index);
                });

            },
        }

        // option渲染方法
        function optionRendering(data, value, text) {
            var optionInf = '<option value="">请选择</option>';
            data.forEach(function (item) {
                optionInf += '<option value="'+ item[value] +'">'+ item[text] +'</option>';
            })
            return optionInf;
        }

        var $table1 = zzpUtils.table({
            elem: '#table1',
            isApi: true,
            pagination:true,
            // url: '/wmsCustomerFileConsignee/list/'+khid,
            columns: [
                {
                    field: '',
                    checkbox: true,
                    clickToSelect:true
                }, {
                    field: 'num',
                    title: '序号',
                    formatter: function (value, row, index) {
                        return index+1;
                    }
                },{
                    field: 'xxdz',
                    title: '详细地址',
                },{
                    field: 'lxr',
                    title: '联系人姓名'
                },{
                    field: 'lxdh',
                    title: '联系人电话'
                },{
                    field: 'sheng',
                    title: '省份',
                },{
                    field: 'shi',
                    title: '城市',
                },{
                    field: 'caozuo',
                    title: '操作',
                    events: operateEvent,
                    formatter: operateFormatter
                }],
            queryParams: function () {//查询条件
                return  zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
        });
        function operateFormatter(value, row, index) {
            var str="";
            if(row.sfyx==0){//无效
                return [
                    '<a class="layui-btn layui-btn-xs " id="enable">启用</a>',
                ].join('')
            }else{
                if(row.sfmr==0){//非默认
                    return [
                        '<a class="layui-btn layui-btn-xs " id="editRow">编辑</a>',
                        '<a class="layui-btn layui-btn-xs " id="default">默认</a>',
                        '<a class="layui-btn layui-btn-danger layui-btn-xs " id="deleteBtn">作废</a>',

                    ].join('')
                }else if(row.sfmr==1){//默认
                    return [
                        '<a class="layui-btn layui-btn-xs " id="editRow">编辑</a>',
                        '<a class="layui-btn layui-btn-xs " id="undefault">取消默认</a>',
                        '<a class="layui-btn layui-btn-danger layui-btn-xs " id="deleteBtn">作废</a>',
                    ].join('')
                }


            }
        }

        $(".inline-search-btn").on('click',function () {
            zzpUtils.refreshTable("#table1");
            zzpUtils.refreshTable("#table2");
        })

        //收货地址编辑保存
        /*  $("#savebtn").on('click', function () {
         var formObject = {};
         var formArray =$("#form1").serializeArray();
         $.each(formArray,function(i,item){
         formObject[item.name] = item.value;
         });
         var formJson = JSON.stringify(formObject);
         alert(formJson);
         var ids = [];
         var tabledata = $table1.bootstrapTable('getData');
         console.log('tabledata', tabledata);
         $.ajax({
         type: 'post',
         url: '/zxsswms/wmsCustomerFileConsignee/edit',
         contentType: "application/json",
         async: false,
         data: formJson,
         success: function (res) {
         /!*   zzpUtils.refreshTable("#table1");*!/
         $('#table1').bootstrapTable('refresh',{url:'/zxsswms/wmsCustomerFileConsignee/list/'+$("#sskhid1").val()});
         setTimeout(function(){
         /!*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
         parent.layer.close(index); //再执行关闭
         console.info(data);*!/
         top.layer.msg(res.title+","+res.message);

         //刷新父页面
         },500);
         }

         })


         });*/
        form.on("submit(savebtn)", function (data) {
            var formObject = {};
            var formArray =$("#form1").serializeArray();
            $.each(formArray,function(i,item){
                formObject[item.name] = item.value;
            });
            var formJson = JSON.stringify(formObject);
            var tabledata = $table1.bootstrapTable('getData');
            console.log('tabledata', tabledata);
            $.ajax({
                type: 'post',
                url: '/zxsswms/wmsCustomerFileConsignee/edit',
                contentType: "application/json",
                async: false,
                data: formJson,
                success: function (res) {
                    $('#table1').bootstrapTable('refresh',{url:'/zxsswms/wmsCustomerFileConsignee/list/'+$("#sskhid1").val()});
                    setTimeout(function(){
                        $('#form1')[0].reset();
                        /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                         parent.layer.close(index); //再执行关闭
                         console.info(data);*/
                        top.layer.msg(res.title+","+res.message);

                        //刷新父页面
                    },500);
                }

            })

            var formObject = {};
            var formArray =$("#form1").serializeArray();
            $.each(formArray,function(i,item){
                formObject[item.name] = item.value;
            });
            var formJson = JSON.stringify(formObject);
            var ids = [];
            var tabledata = $table1.bootstrapTable('getData');
            console.log('tabledata', tabledata);
            $.ajax({
                type: 'post',
                url: '/zxsswms/wmsCustomerFileConsignee/edit',
                contentType: "application/json",
                async: false,
                data: formJson,
                success: function (res) {
                    /*   zzpUtils.refreshTable("#table1");*/
                    $('#table1').bootstrapTable('refresh',{url:'/zxsswms/wmsCustomerFileConsignee/list/'+$("#sskhid1").val()});
                    setTimeout(function(){
                        /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                         parent.layer.close(index); //再执行关闭
                         console.info(data);*/
                        top.layer.msg(res.title+","+res.message);

                        //刷新父页面
                    },500);
                }

            })
            var tabledata = $table1.bootstrapTable('getData');
            console.log('tabledata', tabledata);
            zzpUtils.refreshTable("#table1");
            return false;
        });


        //删除多选行
        $("#delBtn").on('click', function () {
            $rows = $table1.bootstrapTable('getSelections');
            var tabledata = $table1.bootstrapTable('getData');
            if ($rows.length == 0) {
                layer.msg("请选择一条进行删除");
            } else {

                var id = [];
                $rows.forEach(function (item) {
                    id.push(item.id);
                })
                $.ajax({
                    type: 'post',
                    url: '/zxsswms/wmsCustomerFileConsignee/cancel',
                    contentType: "application/json",
                    async: false,
                    data: JSON.stringify({
                        ids: id,
                    }),
                    success: function (res) {
                        console.info(res);
                        setTimeout(function(){
                            zzpUtils.refreshTable("#table1");
                            /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                             parent.layer.close(index); //再执行关闭
                             console.info(data);*/
                            top.layer.msg(res.title+","+res.message);
                            //刷新父页面
                        },500);
                    }
                })
                /*  $table1.bootstrapTable('remove', {field: 'id', values: id});

                 $table1.bootstrapTable('load', tabledata);*/
            }
//            console.log($rows);
        });
        //添加一行
        /* $("#addbtn").on('click',function () {
         alert($("#sskhid1").val());
         var isRepeat;
         var row={"uuid":Math.random().toString(36),"xxdz":$("#xxdz").val(),"lxr":$("#lxr").val(),"lxdh":$("#lxdh").val(),"sheng":$("#sheng2").val(),"shi":$("#shi2").val(),"sskhid":$("#sskhid1").val()}
         /!*$table1.bootstrapTable('append', row);*!/
         $.ajax({
         type: 'post',
         url: '/zxsswms/wmsCustomerFileConsignee/save',
         contentType: "application/json",
         async: false,
         data: JSON.stringify(row),
         success: function (res) {
         alert("addbtn:"+$("#sskhid1").val());
         /!* zzpUtils.refreshTable("#table1");*!/
         $('#table1').bootstrapTable('refresh',{url:'/zxsswms/wmsCustomerFileConsignee/list/'+$("#sskhid1").val()});
         alert("addbtnss:"+$("#sskhid1").val());
         setTimeout(function(){
         /!*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
         parent.layer.close(index); //再执行关闭
         console.info(data);*!/
         top.layer.msg(res.title+","+res.message);
         //刷新父页面
         },500);
         }
         })

         var tabledata = $table1.bootstrapTable('getData');
         console.log('tabledata', tabledata);
         zzpUtils.refreshTable("#table1");

         /!* if (tabledata.length ===0) {
         $table1.bootstrapTable('append', $rows);
         } else {
         for (var i=0;i<$rows.length;i++){
         isRepeat = tabledata.every(function (item) {
         return (item.id !== $rows[i].id)
         });
         if (!isRepeat){
         break;
         }
         }
         console.log('isRepeat', isRepeat);
         if (isRepeat) {
         $table1.bootstrapTable('append', $rows);
         } else {
         layer.msg('已存在不能重复添加');
         }
         }*!/
         });*/

        form.on("submit(addbtn)", function (data) {
            var isRepeat;
            var row={"uuid":Math.random().toString(36),"xxdz":$("#xxdz").val(),"lxr":$("#lxr").val(),"lxdh":$("#lxdh").val(),"sheng":$("#sheng2").val(),"shi":$("#shi2").val(),"sskhid":$("#sskhid1").val()}
            /*$table1.bootstrapTable('append', row);*/
            $.ajax({
                type: 'post',
                url: '/zxsswms/wmsCustomerFileConsignee/save',
                contentType: "application/json",
                async: false,
                data: JSON.stringify(row),
                success: function (res) {
                    /* zzpUtils.refreshTable("#table1");*/
                    $('#table1').bootstrapTable('refresh',{url:'/zxsswms/wmsCustomerFileConsignee/list/'+$("#sskhid1").val()});
                    setTimeout(function(){
                        $('#form1')[0].reset();
                        /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                         parent.layer.close(index); //再执行关闭
                         console.info(data);*/
                        top.layer.msg(res.title+","+res.message);
                        //刷新父页面
                    },500);
                }
            })

            //  zzpUtils.refreshTable("#table1");
            return false;
        });

        //承运人
        var $table2 = zzpUtils.table({
            elem: '#table2',
            isApi: true,
            pagination:true,
            columns: [

                {
                    field: 'd',
                    checkbox: true,
                    clickToSelect:true
                }, {
                    field: 'cph',
                    title: '车牌号'

                },{
                    field: 'sjxm',
                    title: '司机姓名',
                },{
                    field: 'sjdh',
                    title: '司机电话'
                },{
                    field: 'show_sfyx',
                    title: '激活状态'
                },{
                    field: 'caozuo',
                    title: '操作',
                    events: operateEvent,
                    formatter: operateFormatter2
                }],
            queryParams: function () {//查询条件
                return  zzpUtils.getFormJson($("#searchForm2"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
        });

        function operateFormatter2(value, row, index) {
            if(row.sfyx==0){//无效
                return [
                    '<a class="layui-btn layui-btn-xs " id="enable2">启用</a>',
                ].join('')
            }else{
                return [
                    '<a class="layui-btn layui-btn-danger layui-btn-xs " id="deleteBtn2">删除</a>',
                    '<a class="layui-btn layui-btn-xs " id="editRow2">编辑</a>'
                ].join('')
            }
        }


        form.on("submit(addbtn2)", function (data) {
            var row={"uuid":Math.random().toString(36),"cph":$("#cph").val(),"sjxm":$("#sjxm").val(),"sjdh":$("#sjdh").val(),"sskhid":$("#sskhid2").val()}
            /*   $table2.bootstrapTable('append', row);*/
            $.ajax({
                type: 'post',
                url: '/zxsswms/wmsCustomerFileCarrier/save',
                contentType: "application/json",
                async: false,
                data: JSON.stringify(row),
                success: function (res) {
                    /* zzpUtils.refreshTable("#table2");*/
                    $('#table2').bootstrapTable('refresh',{url:'/zxsswms/wmsCustomerFileCarrier/list/'+$("#sskhid2").val()});
                    setTimeout(function(){
                        $('#form2')[0].reset();
                        /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                         parent.layer.close(index); //再执行关闭
                         console.info(data);*/
                        top.layer.msg(res.title+","+res.message);

                        //刷新父页面
                    },500);
                }
            })

            var tabledata = $table2.bootstrapTable('getData');
            // zzpUtils.refreshTable("#table2");
            return false;

        });

        //承运车辆添加一行
        /*    $("#addbtn2").on('click',function () {
         alert($("#sskhid").val());
         var isRepeat;
         var row={"uuid":Math.random().toString(36),"cph":$("#cph").val(),"sjxm":$("#sjxm").val(),"sjdh":$("#sjdh").val(),"sskhid":$("#sskhid").val()}
         $table2.bootstrapTable('append', row);
         $.ajax({
         type: 'post',
         url: '/zxsswms/wmsCustomerFileCarrier/save',
         contentType: "application/json",
         async: false,
         data: JSON.stringify(row),
         success: function (res) {
         zzpUtils.refreshTable("#table2");
         setTimeout(function(){
         /!*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
         parent.layer.close(index); //再执行关闭
         console.info(data);*!/
         top.layer.msg(res.title+","+res.message);

         //刷新父页面
         },500);
         }
         })

         var tabledata = $table2.bootstrapTable('getData');
         console.log('tabledata', tabledata);
         zzpUtils.refreshTable("#table2");
         });*/

        //承运车辆编辑保存
        form.on("submit(savebtn2)", function (data) {
            var formObject = {};
            var formArray =$("#form2").serializeArray();
            $.each(formArray,function(i,item){
                formObject[item.name] = item.value;
            });
            var formJson = JSON.stringify(formObject);
            var tabledata = $table2.bootstrapTable('getData');
            $.ajax({
                type: 'post',
                url: '/zxsswms/wmsCustomerFileCarrier/edit',
                contentType: "application/json",
                async: false,
                data: formJson,
                success: function (res) {
                    /*zzpUtils.refreshTable("#table2");*/
                    $('#table2').bootstrapTable('refresh',{url:'/zxsswms/wmsCustomerFileCarrier/list/'+$("#sskhid2").val()});
                    setTimeout(function(){
                        $('#form2')[0].reset();
                        /*     var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                         parent.layer.close(index); //再执行关闭*/
                        top.layer.msg(res.title+","+res.message);
                        //刷新父页面
                    },500);
                }
            })
            var tabledata = $table2.bootstrapTable('getData');
            console.log('tabledata', tabledata);
            zzpUtils.refreshTable("#table2");
            return false;

        });

        /* $("#savebtn2").on('click', function () {
         var formObject = {};
         var formArray =$("#form2").serializeArray();
         $.each(formArray,function(i,item){
         formObject[item.name] = item.value;
         });
         var formJson = JSON.stringify(formObject);
         alert(formJson);
         var ids = [];
         var tabledata = $table2.bootstrapTable('getData');
         console.log('tabledata', tabledata);
         $.ajax({
         type: 'post',
         url: '/zxsswms/wmsCustomerFileCarrier/edit',
         contentType: "application/json",
         async: false,
         data: formJson,
         success: function (res) {
         zzpUtils.refreshTable("#table2");
         setTimeout(function(){
         /!*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
         parent.layer.close(index); //再执行关闭
         console.info(data);*!/
         top.layer.msg(res.title+","+res.message);
         //刷新父页面
         },500);
         }
         })
         });*/


        var $table3 = zzpUtils.table({
            elem: '#table3',
            isApi: true,
            pagination:false,
            url: '/wmsCustomerFileWarehouse/list',
            columns: [
                {
                    field: '',
                    checkbox: true,
                    clickToSelect:true
                }, {
                    field: 'name',
                    title: '仓库名称'
                }],
            queryParams: function () {//查询条件
                return  zzpUtils.getFormJson($("#searchForm3"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
        });

        $(".warehouseSave").on('click', function () {
            var ids = [];
            var formJson={};
            var rows=$("#table3").bootstrapTable('getSelections');
            rows.forEach(function(value,index,array){
                ids.push(value.id);
            });
            formJson={"id":$("#sskhid3").val(),"ids":ids};
            $.ajax({
                type: 'post',
                url: '/zxsswms/wmsCustomerFileWarehouse/save',
                contentType: "application/json",
                async: false,
                data: JSON.stringify(formJson),
                success: function (res) {
                    zzpUtils.refreshTable("#table3");
                    setTimeout(function(){
                        top.layer.msg(res.title+","+res.message);
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        console.info(data);

                        //刷新父页面
                    },500);
                }
            })
        });


    });

</script>
</html>